package com.ltxtiyu.video.api;

import com.alibaba.dubbo.config.annotation.Reference;
import com.ltxtiyu.video.common.ConfigConstant;
import com.ltxtiyu.video.common.DataGridParam;
import com.ltxtiyu.video.service.app.MomentService;
import com.ltxtiyu.video.tool.ParamTool;
import com.ltxtiyu.video.tool.Tool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/apiMoment")
public class ApiMoment {
    @Reference
    MomentService momentService;

    /**
     * 查询个人动态列表
     * @param request
     * @return
     */
    @RequestMapping("/listMomentForPerson")
    public String listMomentForPerson(HttpServletRequest request){
        String userId = (String) request.getAttribute("userId");
        Map<String, String> params = ParamTool.requestToParamMap(request);
        DataGridParam dgp = Tool.genDataGridParam(request);
        Integer start = (dgp.getPage() - 1) * dgp.getRows();
        Integer rows = dgp.getRows();
        params.put("start", String.valueOf(start));
        params.put("rows", String.valueOf(rows));
        params.put("userId",userId);
        return momentService.listMomentForPerson(params);
    }

    /**
     * 查询关注动态列表
     * @param request
     * @return
     */
    @RequestMapping("/listMomentForFollow")
    public String listMomentForFollow(HttpServletRequest request){
        String userId = (String) request.getAttribute("userId");
        Map<String, String> params = ParamTool.requestToParamMap(request);
        DataGridParam dgp = Tool.genDataGridParam(request);
        Integer start = (dgp.getPage() - 1) * dgp.getRows();
        Integer rows = dgp.getRows();
        params.put("start", String.valueOf(start));
        params.put("rows", String.valueOf(rows));
        params.put("userId",userId);
        return momentService.listMomentForFollow(params);
    }

    /**
     * 推荐页动态列表
     * @param request
     * @return
     */
    @RequestMapping("/listMomentForRecommend")
    public String listMomentForRecommend(HttpServletRequest request){
        String userId = (String) request.getAttribute("userId");
        Map<String, String> params = ParamTool.requestToParamMap(request);
        /*DataGridParam dgp = Tool.genDataGridParam(request);
        Integer start = (dgp.getPage() - 1) * dgp.getRows();
        Integer rows = dgp.getRows();
        params.put("start", String.valueOf(start));*/
        params.put("rows",String.valueOf(ConfigConstant.PAGE_RECOMMEND_ROWS));
        params.put("userId",userId);
        return momentService.listMomentForRecommend(params);
    }



    /**
     * 修改动态权限
     * @param request
     * @return
     */
    @RequestMapping("/updateMomentPermission")
    public String updateMomentPermission(HttpServletRequest request){
        String userId = (String) request.getAttribute("userId");
        Map<String, String> params = ParamTool.requestToParamMap(request);
        params.put("userId",userId);
        return momentService.updateMomentPermission(params);
    }

    /**
     * 删除动态
     * @param request
     * @return
     */
    @RequestMapping("/deleteMoment")
    public String deleteMoment(HttpServletRequest request){
        String userId = (String) request.getAttribute("userId");
        Map<String, String> params = ParamTool.requestToParamMap(request);
        params.put("userId",userId);
        return momentService.deleteMoment(params);
    }

    /**
     * 评论动态
     * @param request
     * @return
     */
    @RequestMapping("/commentMoment")
    public String commentMoment(HttpServletRequest request){
        String userId = (String) request.getAttribute("userId");
        Map<String, String> params = ParamTool.requestToParamMap(request);
        params.put("userId",userId);
        return momentService.commentMoment(params);
    }

    /**
     * 获取动态的评论列表
     * @param request
     * @return
     */
    @RequestMapping("/listComment")
    public String listComment(HttpServletRequest request){
        String userId = (String) request.getAttribute("userId");
        Map<String, String> params = ParamTool.requestToParamMap(request);
        DataGridParam dgp = Tool.genDataGridParam(request);
        Integer start = (dgp.getPage() - 1) * dgp.getRows();
        Integer rows = dgp.getRows();
        params.put("start", String.valueOf(start));
        params.put("rows", String.valueOf(rows));
        params.put("userId",userId);
        return momentService.listComment(params);
    }

    /**
     * 删除评论
     * @param request
     * @return
     */
    @RequestMapping("/deleteComment")
    public String deleteComment(HttpServletRequest request){
        String userId = (String) request.getAttribute("userId");
        Map<String, String> params = ParamTool.requestToParamMap(request);
        params.put("userId",userId);
        return momentService.deleteComment(params);
    }

    /**
     * 点赞动态(视频)
     * @param request
     * @return
     */
    @RequestMapping("/likeMoment")
    public String likeMoment(HttpServletRequest request){
        String userId = (String) request.getAttribute("userId");
        Map<String, String> params = ParamTool.requestToParamMap(request);
        params.put("userId",userId);
        return momentService.likeMoment(params);
    }

    /**
     * 取消点赞动态(视频)
     * @param request
     * @return
     */
    @RequestMapping("/deleteMomentLike")
    public String deleteMomentLike(HttpServletRequest request){
        String userId = (String) request.getAttribute("userId");
        Map<String, String> params = ParamTool.requestToParamMap(request);
        params.put("userId",userId);
        return momentService.deleteMomentLike(params);
    }

    /**
     * 分享动态
     * @param request
     * @return
     */
    @RequestMapping("/share")
    public String shareMoment(HttpServletRequest request){
        Map<String, String> params = ParamTool.requestToParamMap(request);
        return momentService.shareMoment(params);
    }


    /**
     * 发布个人动态
     * @param request
     * @return
     */
    @RequestMapping("/addMoment")
    public String addMoment(HttpServletRequest request){
        String userId = (String) request.getAttribute("userId");
        Map<String, String> params = ParamTool.requestToParamMap(request);
        params.put("userId",userId);
        return momentService.addMoment(params);
    }

    /**
     * 获取视频上传凭证和videoId
     * @param request
     * @return
     */
    @RequestMapping("/createUploadVideo")
    public String createUploadVideo(HttpServletRequest request){
        Map<String, String> params = ParamTool.requestToParamMap(request);
        return momentService.createUploadVideo(params);
    }

    /**
     * 查询动态详情
     * @param request
     * @return
     */
    @RequestMapping("/singleMoment")
    public String singleMoment(HttpServletRequest request){
        String userId = (String) request.getAttribute("userId");
        Map<String, String> params = ParamTool.requestToParamMap(request);
        params.put("userId",userId);
        return momentService.singleMoment(params);
    }



}
